import datetime

from starlette.background import BackgroundTasks

from items.response import GenericResponse
from items.task import Task
from service.task_service import TaskService


def get_originality_check_task(
        task_id: int

):
    """ 获取上下文 """
    task_service = TaskService()
    task = task_service.get_task(task_id)

    return GenericResponse(
        now=int(datetime.datetime.now().timestamp()),
        data={
            "originality": {
                "status": task.get("status"),
                # "search_engine": "baidu",
                # "originality_details": task.get("originality_details")
            },
            "originality_score": task.get("originality_score"),
            "desc": ""
        }
    )


def create_originality_check_task(
        task: Task,
        background_tasks: BackgroundTasks
):
    """
    创建上下文
    :param task: 待检测的任务对象
    :param background_tasks: 后台任务
    :return: 任务id
    """
    task_service = TaskService()
    task_id = task_service.create_originality_check_task(**task.dict(), background_tasks=background_tasks)
    return GenericResponse(
        now=int(datetime.datetime.now().timestamp()),
        data={
            "task_id": task_id
        }
    )


def main():
    pass


if __name__ == '__main__':
    main()
